package com.yaosheng.thread.threadPool;

import java.sql.Time;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * Created by yaosheng on 2021/7/6.
 */
public class CachePoolTest {

    public static void main(String[] args) throws InterruptedException {

        ExecutorService service = Executors.newCachedThreadPool ();
        System.out.println (service);
        for(int i = 0;i < 10;i ++){
            service.execute ( () -> {
                try{
                    TimeUnit.SECONDS.sleep (500);
                } catch (InterruptedException e) {
                    e.printStackTrace ();
                }
                System.out.println (Thread.currentThread ().getName ());
            });
        }

        System.out.println (service);
        TimeUnit.SECONDS.sleep (80);
        System.out.println (service);
    }
}
